<?php

namespace common\logics;

use Yii;
use yii\helpers\Inflector;

/**
 * 退货流程逻辑器
 *
 * @author emhome <emhome@163.com>
 * @since 2.0
 */
class ReturnLogic extends \common\base\Model {

    /**
     * 主线流程
     */
    public function getMasterFull() {
        return [
            [
                'name' => 'apply',
                'text' => '提交申请',
                'children' => [
                    [
                        'name' => 'audit',
                        'text' => '商家审核',
                        'children' => [
                            [
                                'name' => 'audit_reject',
                                'text' => '商家审核-拒绝',
                                'children' => [
                                    [
                                        'name' => 'audit_reject_cancel',
                                        'text' => '退款申请',
                                        'to' => 'cancel',
                                    ],
                                    [
                                        'name' => 'audit_reject_intervene',
                                        'text' => '平台介入',
                                        'children' => [
                                            [
                                                'name' => 'audit_reject_intervene_cancel',
                                                'text' => '退款申请',
                                                'to' => 'cancel',
                                            ],
                                            [
                                                'name' => 'audit_reject_intervene_allow',
                                                'text' => '通过申请',
                                                'to' => 'return',
                                            ],
                                            [
                                                'name' => 'audit_reject_intervene_refund',
                                                'text' => '平台退款',
                                                'to' => 'refund',
                                            ],
                                        ],
                                    ],
                                ],
                            ],
                            [
                                'name' => 'audit_allow',
                                'text' => '商家审核-通过',
                                'children' => [
                                    [
                                        'name' => 'return',
                                        'text' => '买家退回商品',
                                        'children' => [
                                            [
                                                'name' => 'return_cancel',
                                                'text' => '取消服务申请',
                                                'to' => 'cancel',
                                            ],
                                            [
                                                'name' => 'return_submit',
                                                'text' => '提交退回商品物流信息',
                                                'children' => [
                                                    [
                                                        'name' => 'receive',
                                                        'text' => '商家收货',
                                                        'children' => [
                                                            [
                                                                'name' => 'receive_not_received',
                                                                'text' => '商家收货-未收到退回商品',
                                                                'children' => [
                                                                    [
                                                                        'name' => 'receive_not_received_cancel',
                                                                        'text' => '退款申请',
                                                                        'to' => 'cancel',
                                                                    ],
                                                                    [
                                                                        'name' => 'receive_not_received_intervene',
                                                                        'text' => '平台介入',
                                                                        'children' => [
                                                                            [
                                                                                'name' => 'receive_not_received_intervene_cancel',
                                                                                'text' => '退款申请',
                                                                                'to' => 'cancel',
                                                                            ],
                                                                            [
                                                                                'name' => 'receive_not_received_intervene_confirm_received',
                                                                                'text' => '商家收货-确认收到商品',
                                                                                'to' => 'refund',
                                                                            ],
                                                                            [
                                                                                'name' => 'receive_not_received_intervene_refund',
                                                                                'text' => '平台退款',
                                                                                'to' => 'refund',
                                                                            ],
                                                                            [
                                                                                'name' => 'receive_not_received_intervene_close',
                                                                                'text' => '关闭服务申请',
                                                                                'to' => 'close',
                                                                            ],
                                                                        ],
                                                                    ],
                                                                ],
                                                            ],
                                                            [
                                                                'name' => 'receive_confirm_received',
                                                                'text' => '商家收货-确认收到商品',
                                                                'children' => [
                                                                    [
                                                                        'name' => 'refund',
                                                                        'text' => '退款',
                                                                        'children' => [
                                                                            [
                                                                                'name' => 'refund_fail',
                                                                                'text' => '退款-失败',
                                                                                'children' => [
                                                                                    [
                                                                                        'name' => 'refund_fail_intervene_finish',
                                                                                        'text' => '人工退款',
                                                                                        'to' => 'finish',
                                                                                    ],
                                                                                    [
                                                                                        'name' => 'refund_fail_intervene_refund_bank',
                                                                                        'text' => '系统退款',
                                                                                        'to' => 'bank',
                                                                                    ],
                                                                                ],
                                                                            ],
                                                                            [
                                                                                'name' => 'refund_allow',
                                                                                'text' => '退款-审核通过',
                                                                                'children' => [
                                                                                    [
                                                                                        'name' => 'bank',
                                                                                        'text' => '银行退款',
                                                                                        'children' => [
                                                                                            [
                                                                                                'name' => 'bank_fail',
                                                                                                'text' => '未到账',
                                                                                                'children' => [
                                                                                                    [
                                                                                                        'name' => 'bank_fail_intervene_finish',
                                                                                                        'text' => '人工退款',
                                                                                                        'to' => 'finish',
                                                                                                    ],
                                                                                                    [
                                                                                                        'name' => 'bank_fail_intervene_bank_again',
                                                                                                        'text' => '系统退款',
                                                                                                        'to' => 'bank',
                                                                                                    ],
                                                                                                ],
                                                                                            ],
                                                                                            [
                                                                                                'name' => 'finish',
                                                                                                'text' => '完成',
                                                                                            ],
                                                                                        ],
                                                                                    ],
                                                                                ],
                                                                            ],
                                                                        ],
                                                                    ],
                                                                ],
                                                            ],
                                                        ],
                                                    ],
                                                ],
                                            ],
                                        ],
                                    ],
                                ],
                            ],
                        ],
                    ],
                    [
                        'name' => 'return',
                        'text' => '买家退回商品',
                        'hidden' => true,
                    ],
                    [
                        'name' => 'receive',
                        'text' => '商家收货',
                    ],
                    [
                        'name' => 'refund',
                        'text' => '退款',
                    ],
                    [
                        'name' => 'bank',
                        'text' => '银行退款',
                        'hidden' => true,
                    ],
                    [
                        'name' => 'finish',
                        'text' => '完成',
                    ],
                ],
            ],
            [
                'name' => 'audit',
                'text' => '商家审核',
            ],
            [
                'name' => 'return',
                'text' => '买家退回商品',
                'hidden' => true,
            ],
            [
                'name' => 'receive',
                'text' => '商家收货',
            ],
            [
                'name' => 'refund',
                'text' => '退款',
            ],
            [
                'name' => 'finish',
                'text' => '完成',
            ],
        ];
    }

    /**
     * 主线流程
     */
    public function getMaster() {
        return [
            [
                'name' => 'apply',
                'text' => '提交申请',
            ],
            [
                'name' => 'audit',
                'text' => '商家审核',
            ],
            [
                'name' => 'return',
                'text' => '买家退回商品',
                'hidden' => true,
            ],
            [
                'name' => 'receive',
                'text' => '商家收货',
            ],
            [
                'name' => 'refund',
                'text' => '退款',
            ],
            [
                'name' => 'finish',
                'text' => '完成',
            ],
        ];
    }

    /**
     * 买家申请操作
     */
    public function getMasterApplyHandle() {
        return [
            [
                'name' => 'buyer',
                'handles' => [
                    [
                        'name' => 'cancel',
                        'text' => '取消申请',
                    ],
                ],
            ],
            [
                'name' => 'store',
                'handles' => [],
            ],
            [
                'name' => 'platform',
                'handles' => [],
            ],
            [
                'name' => 'system',
                'handles' => [],
            ],
        ];
    }

    /**
     * 商家审核操作
     */
    public function getMasterAuditHandle() {
        return [
            [
                'name' => 'buyer',
                'handles' => [
                    [
                        'name' => 'cancel',
                        'text' => '取消申请',
                    ],
                ],
            ],
            [
                'name' => 'store',
                'handles' => [
                    [
                        'name' => 'allow',
                        'text' => '审核通过',
                    ],
                    [
                        'name' => 'reject',
                        'text' => '审核拒绝',
                    ],
                ],
            ],
            [
                'name' => 'platform',
                'handles' => [],
            ],
            [
                'name' => 'system',
                'handles' => [],
            ],
        ];
    }

    /**
     * 买家退回商品操作
     */
    public function getMasterReturnHandle() {
        return [
            [
                'name' => 'buyer',
                'handles' => [
                    [
                        'name' => 'cancel',
                        'text' => '取消申请',
                    ],
                    [
                        'name' => 'submitFillLogistics',
                        'text' => '填写物流信息',
                    ],
                ],
            ],
            [
                'name' => 'store',
                'handles' => [],
            ],
            [
                'name' => 'platform',
                'handles' => [],
            ],
            [
                'name' => 'system',
                'handles' => [],
            ],
        ];
    }

    /**
     * 商家收货操作
     */
    public function getMasterReceiveHandle() {
        return [
            [
                'name' => 'buyer',
                'handles' => [
                    [
                        'name' => 'cancel',
                        'text' => '取消申请',
                    ],
                    [
                        'name' => 'updateLogistics',
                        'text' => '修改物流信息',
                    ],
                ],
            ],
            [
                'name' => 'store',
                'handles' => [
                    [
                        'name' => 'notReceived',
                        'text' => '未收到退回商品',
                    ],
                    [
                        'name' => 'confirmReceipt',
                        'text' => '确认收货',
                    ],
                ],
            ],
            [
                'name' => 'platform',
                'handles' => [],
            ],
            [
                'name' => 'system',
                'handles' => [],
            ],
        ];
    }

    /**
     * 平台退款操作
     */
    public function getMasterRefundHandle() {
        return [
            [
                'name' => 'buyer',
                'handles' => [],
            ],
            [
                'name' => 'store',
                'handles' => [],
            ],
            [
                'name' => 'platform',
                'handles' => [
                    [
                        'name' => 'allow',
                        'text' => '审核通过',
                    ],
                    [
                        'name' => 'reject',
                        'text' => '审核拒绝',
                    ],
                ],
            ],
            [
                'name' => 'system',
                'handles' => [],
            ],
        ];
    }

    /**
     * 分支操作（平台审核拒绝）
     */
    public function getMasterRefundReject() {
        return [
            [
                'name' => 'buyer',
                'handles' => [
                    [
                        'name' => 'intervene',
                        'text' => '申请平台介入',
                    ],
                ],
            ],
            [
                'name' => 'store',
                'handles' => [
                    [
                        'name' => 'storeRefund',
                        'text' => '自行退款',
                    ],
                    [
                        'name' => 'intervene',
                        'text' => '申请平台介入',
                    ],
                ],
            ],
            [
                'name' => 'platform',
                'handles' => [],
            ],
            [
                'name' => 'system',
                'handles' => [],
            ],
        ];
    }

    /**
     * 分支操作（商家审核拒绝）
     */
    public function getMasterAuditReject() {
        return [
            [
                'name' => 'buyer',
                'handles' => [
                    [
                        'name' => 'cancel',
                        'text' => '取消申请',
                    ],
                    [
                        'name' => 'intervene',
                        'text' => '申请平台介入',
                    ],
                ],
            ],
            [
                'name' => 'store',
                'handles' => [],
            ],
            [
                'name' => 'platform',
                'handles' => [],
            ],
            [
                'name' => 'system',
                'handles' => [],
            ],
        ];
    }

    /**
     * 分支操作（平台干预）-退款环节干预
     */
    public function getMasterRefundIntervene() {
        return [
            [
                'name' => 'buyer',
                'handles' => [
                    [
                        'name' => 'service',
                        'text' => '三方客服',
                    ],
                ],
            ],
            [
                'name' => 'store',
                'handles' => [
                    [
                        'name' => 'storeRefund',
                        'text' => '自行退款',
                    ],
                    [
                        'name' => 'service',
                        'text' => '三方客服',
                    ],
                ],
            ],
            [
                'name' => 'platform',
                'handles' => [
                    [
                        'name' => 'refund',
                        'text' => '平台退款',
                    ],
                    [
                        'name' => 'punish',
                        'text' => '处罚商家',
                    ],
                    [
                        'name' => 'finish',
                        'text' => '服务完成',
                    ],
                    [
                        'name' => 'service',
                        'text' => '三方客服',
                    ],
                ],
            ],
            [
                'name' => 'system',
                'handles' => [],
            ],
        ];
    }

    /**
     * 分支操作（平台干预）-审核环节干预
     */
    public function getMasterAuditIntervene() {
        return [
            [
                'name' => 'buyer',
                'handles' => [
                    [
                        'name' => 'cancel',
                        'text' => '取消申请',
                    ],
                    [
                        'name' => 'service',
                        'text' => '三方客服',
                    ],
                ],
            ],
            [
                'name' => 'store',
                'handles' => [
                    [
                        'name' => 'allow',
                        'text' => '通过申请',
                    ],
                    [
                        'name' => 'service',
                        'text' => '三方客服',
                    ],
                ],
            ],
            [
                'name' => 'platform',
                'handles' => [
                    [
                        'name' => 'refund',
                        'text' => '平台退款',
                    ],
                    [
                        'name' => 'punish',
                        'text' => '处罚商家',
                    ],
                    [
                        'name' => 'service',
                        'text' => '三方客服',
                    ],
                ],
            ],
            [
                'name' => 'system',
                'handles' => [],
            ],
        ];
    }

    /**
     * 分支操作（商家未收到退回商品）
     */
    public function getMasterReceiveNotReceived() {
        return [
            [
                'name' => 'buyer',
                'handles' => [
                    [
                        'name' => 'cancel',
                        'text' => '取消申请',
                    ],
                    [
                        'name' => 'intervene',
                        'text' => '申请平台介入',
                    ],
                ],
            ],
            [
                'name' => 'store',
                'handles' => [],
            ],
            [
                'name' => 'platform',
                'handles' => [],
            ],
            [
                'name' => 'system',
                'handles' => [],
            ],
        ];
    }

    /**
     * 分支操作（平台干预）-退回商品确认收货环节干预
     */
    public function getMasterReceiveIntervene() {
        return [
            [
                'name' => 'buyer',
                'handles' => [
                    [
                        'name' => 'cancel',
                        'text' => '取消申请',
                    ],
                    [
                        'name' => 'service',
                        'text' => '三方客服',
                    ],
                ],
            ],
            [
                'name' => 'store',
                'handles' => [
                    [
                        'name' => 'confirmReceipt',
                        'text' => '确认收货',
                    ],
                    [
                        'name' => 'service',
                        'text' => '三方客服',
                    ],
                ],
            ],
            [
                'name' => 'platform',
                'handles' => [
                    [
                        'name' => 'refund',
                        'text' => '平台退款',
                    ],
                    [
                        'name' => 'punish',
                        'text' => '处罚商家',
                    ],
                    [
                        'name' => 'close',
                        'text' => '关闭服务申请',
                    ],
                    [
                        'name' => 'service',
                        'text' => '三方客服',
                    ],
                ],
            ],
            [
                'name' => 'system',
                'handles' => [],
            ],
        ];
    }

}
